package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import model.FileParser;
import model.Manuscript;
import model.Status;

/**
 * Class for a status listener.
 * @author Sarah George
 * @version Autumn 2012.
 */
public class StatusListener implements ActionListener {
	
	/**
	 * Field to hold the paper on which the decision will be made.
	 */
	private Manuscript my_paper;
	
	/**
	 * Field to hold the FileParser.
	 */
	private FileParser my_parser;
	
	/**
	 * Constructor for a status listener.
	 * @param the_paper the paper
	 * @param the_parser the FileParser
	 */
	public StatusListener(Manuscript the_paper, FileParser the_parser) {
		super();
		my_paper = the_paper;
		my_parser = the_parser;
	}

	/**
	 * Method to set the Status from the status combobox.
	 * @param arg0 the action event that triggers this method.
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		@SuppressWarnings("unchecked")
		JComboBox<Status> cb = (JComboBox<Status>)arg0.getSource();
        Status st = (Status)cb.getSelectedItem();
		my_paper.setMy_status(st);
		if(my_parser.writeManuscript(my_paper))
		{
			JOptionPane.showMessageDialog(null, "You have successfully changed the status of this paper to: " + st);
		} else {
			JOptionPane.showMessageDialog(null, "There was a problem changing the status: " + st);
		}
	}
}//End class Status Listener.